////////////////////////////////////////////////////////////////////////////////
// Filename: Model3DInstance.h
////////////////////////////////////////////////////////////////////////////////
#ifndef _PHYSICMANAGER_H_
#define _PHYSICMANAGER_H_

//////////////
// INCLUDES //
//////////////

#include <btBulletDynamicsCommon.h>
#include <Windows.h>
#include <xnamath.h>
#include <BulletDynamics/Character/btCharacterControllerInterface.h>

void ConvertVector( XMFLOAT3 &pOrigine, btVector3 &pResult );
void ConvertVector( btVector3 &pResult, XMFLOAT3 &pOrigine );
XMFLOAT4X4 ConvertMatrix( btTransform &trn );

struct rayTestResult
{
	bool hit;
	XMFLOAT3 position;
	XMFLOAT3 normal;
	void* userPointer;
};

class PhysicManager
{
public:
	static PhysicManager* Instance();

	PhysicManager();
	PhysicManager(const PhysicManager&);
	PhysicManager operator=(PhysicManager const&);
	~PhysicManager();

	bool Initialize();
	void Uninit();

	void Update(int pElapsedTime);

	void addRigidBody(btRigidBody* pRigidBody);
	void addCharacter(btCharacterControllerInterface* pCharacterController);
	void addCollisionObject(btCollisionObject* pObject);

	void TestRayTest(XMFLOAT3 pStart, XMFLOAT3 pOrientation, rayTestResult *result);

private:
	btBroadphaseInterface* mBroadphase;
	btDefaultCollisionConfiguration* mCollisionConfiguration;
	btCollisionDispatcher* mDispatcher;
	btSequentialImpulseConstraintSolver* mSolver;
	btDiscreteDynamicsWorld* mDynamicsWorld;

	static PhysicManager* mInstance;
};

#endif
